//
//  WQAnimationTool.m
//  WQTransitionAnimationTool
//
//  Created by Xiang on 2021/5/12.
//

#import "WQAnimationTool.h"

@implementation WQAnimationTool

+ (CATransition *)setAnimationWithType:(WQAnimationType)type
{
    //创建CATransition对象
    CATransition *animation = [CATransition animation];
    NSString *animationType = nil;
    //设置运动时间
    switch (type) {
        case WQAnimationTypeFade://淡入淡出
        {
            animationType =kCATransitionFade;
        }
            break;
        case WQAnimationTypePush://推挤
        {
            animationType =kCATransitionPush;
        }
            
            break;
            
        case WQAnimationTypeReveal://揭开
        {
            
            animationType =kCATransitionReveal;
        }
            
            break;
            
        case WQAnimationTypeMoveIn://覆盖
        {
            
            animationType =kCATransitionMoveIn;
        }
            break;
            
        case WQAnimationTypeCube://立方体
        {
            
            animationType =@"cube";
        }
            break;
            
        case WQAnimationTypeSuckEffect://吮吸
        {
            animationType =@"suckEffect";
        }
            break;
            
        case WQAnimationTypeOglFlip://翻转
        {
            
            animationType =@"oglFlip";
        }
            break;
            
        case WQAnimationTypeRippleEffect://波纹
        {
            
            animationType =@"rippleEffect";
        }
            break;
            
        case WYAnimationTypePageCurl://翻页
        {
            
            animationType =@"pageCurl";
        }
            break;
            
        case WQAnimationTypePageUnCurl://反翻页
        {
            
            animationType =@"pageUnCurl";
        }
            break;
        case WQAnimationTypeCameraIrisHollowOpen://开镜头
        {
            
            animationType =@"cameraIrisHollowOpen";
        }
            break;
            
        case WQAnimationTypeCameraIrisHollowClose://关镜头
        {
            
            animationType =@"cameraIrisHollowClose";
        }
            break;
            
        case WQAnimationTypeCurlDown://下翻页
        {
            
            animationType =@"pageUnCurl";
        }
            break;
            
        case WQAnimationTypeCurlUp://上翻页
        {
            
            animationType =@"pageUnCurl";
        }
            break;
            
        case WQAnimationTypeFlipFromLeft://左翻转
        {
            
            animationType =@"pageUnCurl";
        }
            break;
            
        case WQAnimationTypeFlipFromRight://右翻转
        {
            animationType =@"pageUnCurl";
        }
            break;
            
        default:
            break;
    }
    //设置运动type
    animation.type = animationType;
    return animation;
}
+ (NSString *)setTranstionDirectionWithDirection:(WQTransitionDirection)transitionDirection
{
    NSString *subtype = nil;
    switch (transitionDirection) {
        case WQTransitionDirectionNone:
        {
            
        }
        case WQTransitionDirectionBottom:
        {
            subtype =kCATransitionFromBottom;
        }
            break;
            
        case WQTransitionDirectionLeft:
        {
            
            subtype =kCATransitionFromLeft;
        }
            break;
        case WQTransitionDirectionRight:
        {
            subtype =kCATransitionFromRight;
        }
            break;
        case WQTransitionDirectionTop:
        {
            subtype =kCATransitionFromTop;
        }
            break;
        default:
            break;
    }
    return subtype;
}
+ (void)presentViewControllerWithAnimationType:(WQAnimationType)type transitionDirection:(WQTransitionDirection)transitionDirection duration:(NSTimeInterval)duration fromVC:(UIViewController *)fromViewController toVC:(UIViewController *)toViewController completion:(void (^)(void))completion;
{
    //创建CATransition对象 设置动画类型
    CATransition *animation = [self setAnimationWithType:type];
    //设置运动时间
    animation.duration = duration ? duration : 1.f;
    //设置方向
    NSString *subtype = [self setTranstionDirectionWithDirection:transitionDirection];
    if (subtype != nil) {
        //设置子类
        animation.subtype = subtype;
    }
    //设置运动速度
    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
    [fromViewController.view.window.layer addAnimation:animation forKey:@"animation"];
    //animated 一定要是NO
    toViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [fromViewController presentViewController:toViewController animated:NO completion:completion];
}


@end
